package o;

import android.content.Context;
import android.database.Cursor;
import android.net.Uri;
import android.os.Bundle;
import android.provider.Settings.Secure;
import com.huawei.android.content.pm.PackageManagerEx;
import com.huawei.android.os.SystemPropertiesEx;
import com.huawei.displayengine.DisplayEngineInterface;
import com.huawei.gamebox.plugin.gameservice.bean.GameInfo;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import o.bif.a;
import o.bif.b;
import o.bif.c;
import o.bif.f;
import o.bif.g;
import o.bif.h;
import o.bif.i;
import o.bif.j;
import org.jetbrains.annotations.NotNull;

public class bii {

    public static class e {
        private boolean ˎ;
        private a ˏ;

        public boolean ॱ() {
            return this.ˎ;
        }

        public void ˋ(boolean z) {
            this.ˎ = z;
        }

        public a ˊ() {
            return this.ˏ;
        }

        public void ॱ(a aVar) {
            this.ˏ = aVar;
        }
    }

    private static boolean ॱˊ() {
        if (big.ʻ() && Secure.getInt(ContentManager.getInstant().getContext().getContentResolver(), "game_power_save_mode", i.NOT_SUPPORT.ˋ()) != i.NOT_SUPPORT.ˋ()) {
            return true;
        }
        return false;
    }

    private static boolean ˊॱ() {
        if (big.ʻ() && Secure.getInt(ContentManager.getInstant().getContext().getContentResolver(), "game_dnd_mode", b.NOT_SUPPORT.ˎ()) != b.NOT_SUPPORT.ˎ()) {
            return true;
        }
        return false;
    }

    public static boolean ॱ() {
        if (!big.ʻ()) {
            return false;
        }
        int i = Secure.getInt(ContentManager.getInstant().getContext().getContentResolver(), "game_deep_nodisturb_mode", o.bif.e.NOT_SUPPORT.ˏ());
        if (i == o.bif.e.OPEN.ˏ() || i == o.bif.e.CLOSE.ˏ()) {
            return true;
        }
        return false;
    }

    private static boolean ˋॱ() {
        if (big.ॱ() && big.ʻ() && Secure.getInt(ContentManager.getInstant().getContext().getContentResolver(), "game_key_control_mode", h.NOT_SUPPORT.ˏ()) != h.NOT_SUPPORT.ˏ()) {
            return true;
        }
        return false;
    }

    private static boolean ʻॱ() {
        if (big.ʻ() && Secure.getInt(ContentManager.getInstant().getContext().getContentResolver(), "game_gesture_disabled_mode", c.NOT_SUPPORT.ˎ()) != c.NOT_SUPPORT.ˎ()) {
            return true;
        }
        return false;
    }

    private static void ˎ(String str, int i) {
        try {
            Secure.putInt(ContentManager.getInstant().getContext().getContentResolver(), str, i);
        } catch (SecurityException e) {
            Logger.e("GameModeRomSupport", "setGameModeStatus error");
        }
    }

    public static void ˋ(i iVar) {
        ˎ("game_power_save_mode", iVar.ˋ());
    }

    public static void ˎ(b bVar) {
        if (Logger.ˎ()) {
            Logger.ˏ("GameModeRomSupport", "setDndStatus:" + bVar.ˎ());
        }
        ˎ("game_dnd_mode", bVar.ˎ());
    }

    public static void ˊ(o.bif.e eVar) {
        if (Logger.ˎ()) {
            Logger.ˏ("GameModeRomSupport", "setDndStatus:" + eVar.ˏ());
        }
        ˎ("game_deep_nodisturb_mode", eVar.ˏ());
    }

    public static void ˎ(g gVar) {
        if (Logger.ˎ()) {
            Logger.ˏ("GameModeRomSupport", "setTotalDndStatus:" + gVar.ˏ());
        }
        if (gVar == g.CLOSE) {
            ˎ(b.CLOSE);
            ˊ(o.bif.e.CLOSE);
        } else if (gVar == g.MSG_DND) {
            ˎ(b.OPEN);
            ˊ(o.bif.e.CLOSE);
        } else if (gVar == g.DEEP_DND) {
            ˎ(b.OPEN);
            ˊ(o.bif.e.OPEN);
        }
    }

    public static void ˋ(h hVar) {
        if (Logger.ˎ()) {
            Logger.ˏ("GameModeRomSupport", "setKeyControlStatus:" + hVar.ˏ());
        }
        ˎ("game_key_control_mode", hVar.ˏ());
    }

    public static void ˏ(c cVar) {
        if (Logger.ˎ()) {
            Logger.ˏ("GameModeRomSupport", "setGestureDisStatus:" + cVar.ˎ());
        }
        ˎ("game_gesture_disabled_mode", cVar.ˎ());
    }

    public static void ˎ(f fVar) {
        if (Logger.ˎ()) {
            Logger.ˏ("GameModeRomSupport", "setSoundToVibStatus:" + fVar.ॱ());
        }
        ˎ("sound_to_vibrate_effect", fVar.ॱ());
    }

    public static void ˎ(j jVar) {
        if (Logger.ˎ()) {
            Logger.ˏ("GameModeRomSupport", "setTripleFinger:" + jVar.ˏ());
        }
        ˎ("game_triple_finger", jVar.ˏ());
    }

    public static i ˎ() {
        int i = Secure.getInt(ContentManager.getInstant().getContext().getContentResolver(), "game_power_save_mode", i.NOT_SUPPORT.ˋ());
        if (Logger.ˎ()) {
            Logger.ˏ("GameModeRomSupport", "getPowerSaveStatus:" + i);
        }
        return i.ॱ(i);
    }

    public static b ˏ() {
        int i = Secure.getInt(ContentManager.getInstant().getContext().getContentResolver(), "game_dnd_mode", b.NOT_SUPPORT.ˎ());
        if (Logger.ˎ()) {
            Logger.ˏ("GameModeRomSupport", "getDndStatus:" + i);
        }
        return b.ˎ(i);
    }

    public static o.bif.e ˊ() {
        int i = Secure.getInt(ContentManager.getInstant().getContext().getContentResolver(), "game_deep_nodisturb_mode", o.bif.e.NOT_SUPPORT.ˏ());
        if (Logger.ˎ()) {
            Logger.ˏ("GameModeRomSupport", "getDeepDndStatus:" + i);
        }
        return o.bif.e.ˊ(i);
    }

    public static g ˋ() {
        o.bif.e ˊ = ˊ();
        if (ˏ() != b.OPEN) {
            return g.CLOSE;
        }
        if (ˊ == o.bif.e.OPEN) {
            return g.DEEP_DND;
        }
        return g.MSG_DND;
    }

    public static h ᐝ() {
        int i = Secure.getInt(ContentManager.getInstant().getContext().getContentResolver(), "game_key_control_mode", h.NOT_SUPPORT.ˏ());
        if (Logger.ˎ()) {
            Logger.ˏ("GameModeRomSupport", "getKeyControlStatus:" + i);
        }
        return h.ˎ(i);
    }

    public static c ʽ() {
        int i = Secure.getInt(ContentManager.getInstant().getContext().getContentResolver(), "game_gesture_disabled_mode", c.NOT_SUPPORT.ˎ());
        if (Logger.ˎ()) {
            Logger.ˏ("GameModeRomSupport", "getGestureDisturbStatus:" + i);
        }
        return c.ˊ(i);
    }

    public static f ॱॱ() {
        int i = Secure.getInt(ContentManager.getInstant().getContext().getContentResolver(), "sound_to_vibrate_effect", f.NOT_SUPPORT.ॱ());
        if (Logger.ˎ()) {
            Logger.ˏ("GameModeRomSupport", "getSoundToVibStatus:" + i);
        }
        return f.ˊ(i);
    }

    public static j ʻ() {
        int i = Secure.getInt(ContentManager.getInstant().getContext().getContentResolver(), "game_triple_finger", j.NOT_SUPPORT.ˏ());
        if (Logger.ˎ()) {
            Logger.ˏ("GameModeRomSupport", "getTripleFingerStatus:" + i);
        }
        return j.ˏ(i);
    }

    public static List<String> ˎ(GameInfo gameInfo) {
        List arrayList = new ArrayList();
        Collection ॱˋ = ॱˋ();
        if (!CollectCheck.isEmpty(ॱˋ)) {
            arrayList.addAll(ॱˋ);
        }
        if (ˊॱ()) {
            arrayList.add("game_dnd_mode");
        }
        if (big.ʼ()) {
            arrayList.add("screen_shot");
        }
        if (big.ʽ()) {
            arrayList.add("buoy_record");
        }
        if (big.ʻ()) {
            arrayList.add("net_optim");
        }
        if (ॱˊ()) {
            arrayList.add("game_power_save_mode");
        }
        if (ˋॱ()) {
            arrayList.add("game_key_control_mode");
        }
        if (big.ˊ()) {
            arrayList.add("calling_dnd");
        }
        if (ʻॱ()) {
            arrayList.add("game_gesture_disabled_mode");
        }
        if (big.ˋ()) {
            arrayList.add("sound_to_vibrate_effect");
        }
        if (big.ॱॱ()) {
            arrayList.add("game_triple_finger");
        }
        ˏ(arrayList);
        return arrayList;
    }

    private static void ˏ(List<String> list) {
        if (ॱᐝ() && ˏॱ().ॱ()) {
            list.add("keep_luminance");
        }
    }

    private static List<String> ॱˋ() {
        List arrayList = new ArrayList();
        if (big.ʻ()) {
            if (ContentManager.getInstant().getContext().getResources().getConfiguration().orientation == 2) {
                arrayList.add("virtual_key_setting");
            }
            arrayList.add("device_setting");
        }
        return arrayList;
    }

    public static boolean ˎ(String str) {
        Throwable th;
        Throwable th2;
        Context ˋ = ContentManager.getInstant().getContext();
        if (ˋ == null || dof.ॱ(str)) {
            Logger.e("GameModeRomSupport", "context = null?" + (ˋ == null) + ", packageName = " + str);
            return false;
        }
        Cursor query;
        boolean z;
        try {
            query = ˋ.getContentResolver().query(Uri.parse("content://com.huawei.android.gameassistant.provider/icon_indices"), null, "packagename=?", new String[]{str}, null);
            th = null;
            if (query != null) {
                try {
                    if (query.getCount() <= 0) {
                        z = false;
                        if (query != null) {
                            return z;
                        }
                        if (null == null) {
                            try {
                                query.close();
                                return z;
                            } catch (Throwable th3) {
                                try {
                                    th.addSuppressed(th3);
                                    return z;
                                } catch (Exception e) {
                                    Logger.e("GameModeRomSupport", "query game assistant failed");
                                    return z;
                                }
                            }
                        }
                        query.close();
                        return z;
                    }
                } catch (Throwable th4) {
                    th2 = th4;
                }
            }
            z = true;
            if (query != null) {
                return z;
            }
            if (null == null) {
                query.close();
                return z;
            }
            query.close();
            return z;
        } catch (Exception e2) {
            z = true;
            Logger.e("GameModeRomSupport", "query game assistant failed");
            return z;
        }
        throw th2;
        if (query != null) {
            if (th != null) {
                try {
                    query.close();
                } catch (Throwable th32) {
                    th.addSuppressed(th32);
                }
            } else {
                query.close();
            }
        }
        throw th2;
    }

    public static boolean ʼ() {
        return SystemPropertiesEx.getBoolean("ro.config.hw_multiwindow_optimization", false);
    }

    public static ArrayList<biu.a> ˏ(GameInfo gameInfo) {
        Object arrayList = new ArrayList();
        List list;
        if (ʼ()) {
            List ᐝॱ = ᐝॱ();
            List<biu.a> ˏ = bib.ˏ(gameInfo);
            if (!CollectCheck.isEmpty(ˏ)) {
                for (biu.a aVar : ˏ) {
                    if (big.ˎ(aVar.ॱ()) && !ᐝॱ.contains(aVar.ॱ())) {
                        ᐝॱ.add(aVar.ॱ());
                    }
                }
            }
            list = ᐝॱ;
        } else {
            list = ᐝॱ();
        }
        for (String str : r0) {
            if (!str.equals(gameInfo.getPackageName()) && big.ˎ(str)) {
                biu.a ˏ2 = biu.a.ˏ("free_form|" + str, null, null, null);
                if (ˏ2 != null) {
                    arrayList.add(ˏ2);
                }
                if (big.ˊ(str)) {
                    ˏ2 = biu.a.ˏ("free_form_clone|" + str, null, null, null);
                    if (ˏ2 != null) {
                        arrayList.add(ˏ2);
                        Logger.ˎ("GameModeRomSupport", str + "has cloned app");
                    }
                }
            }
        }
        if (CollectCheck.isEmpty(arrayList)) {
            Logger.ˎ("GameModeRomSupport", "get freeformlist empty");
        }
        return arrayList;
    }

    private static boolean ॱᐝ() {
        boolean z = true;
        if (big.ʻ()) {
            try {
                int supported = new DisplayEngineInterface().getSupported("FEATURE_GAME_DISABLE_AUTO_BRIGHTNESS_MODE");
                Logger.ˎ("GameModeRomSupport", "isSupportKeepLuminance result: " + supported);
                if (supported != 1) {
                    z = false;
                }
                return z;
            } catch (Throwable th) {
                if (Logger.ˎ()) {
                    Logger.e("GameModeRomSupport", "isSupportKeepLuminance Throwable: " + th.getMessage());
                    return false;
                }
                Logger.e("GameModeRomSupport", "isSupportKeepLuminance Throwable.");
                return false;
            }
        }
        Logger.ˎ("GameModeRomSupport", "without install gameassistant");
        return false;
    }

    public static boolean ˊ(a aVar) {
        if (Logger.ˎ()) {
            Logger.ˏ("GameModeRomSupport", "setKeepLuminanceStatus:" + aVar.ˋ());
        }
        try {
            int scene;
            DisplayEngineInterface displayEngineInterface = new DisplayEngineInterface();
            if (aVar == a.OPEN) {
                scene = displayEngineInterface.setScene("SCENE_GAME_DISABLE_AUTO_BRIGHTNESS_MODE", "ACTION_MODE_ON");
            } else {
                scene = displayEngineInterface.setScene("SCENE_GAME_DISABLE_AUTO_BRIGHTNESS_MODE", "ACTION_MODE_OFF");
            }
            if (scene == 1) {
                return true;
            }
            Logger.e("GameModeRomSupport", "setKeepLuminanceStatus rtnCode: " + scene);
            return false;
        } catch (Throwable th) {
            if (Logger.ˎ()) {
                Logger.e("GameModeRomSupport", "setKeepLuminanceStatus Throwable: " + th.getMessage());
            } else {
                Logger.e("GameModeRomSupport", "setKeepLuminanceStatus Throwable.");
            }
            return false;
        }
    }

    public static e ˏॱ() {
        e eVar = new e();
        try {
            DisplayEngineInterface displayEngineInterface = new DisplayEngineInterface();
            Bundle bundle = new Bundle();
            int effect = displayEngineInterface.getEffect("FEATURE_GAME_DISABLE_AUTO_BRIGHTNESS_MODE", "ACTION_MODE_ON", bundle);
            if (effect == 1) {
                a aVar;
                boolean z = bundle.getBoolean("GameDisableAutoBrightnessModeEnable");
                Logger.ˎ("GameModeRomSupport", "getKeepLuminanceStatus OPEN:" + z);
                eVar.ˋ(true);
                if (z) {
                    aVar = a.OPEN;
                } else {
                    aVar = a.CLOSE;
                }
                eVar.ॱ(aVar);
            } else {
                Logger.e("GameModeRomSupport", "getKeepLuminanceStatus result: " + effect);
                eVar.ˋ(false);
                eVar.ॱ(a.CLOSE);
            }
        } catch (Throwable th) {
            if (Logger.ˎ()) {
                Logger.e("GameModeRomSupport", "getKeepLuminanceStatus Throwable: " + th.getMessage());
            } else {
                Logger.e("GameModeRomSupport", "getKeepLuminanceStatus Throwable.");
            }
            eVar.ˋ(false);
            eVar.ॱ(a.CLOSE);
        }
        return eVar;
    }

    private static List<String> ᐝॱ() {
        List<String> ͺ = ͺ();
        Iterator it = ͺ.iterator();
        while (it.hasNext()) {
            if (!big.ˎ((String) it.next())) {
                it.remove();
            }
        }
        return ͺ;
    }

    @NotNull
    public static List<String> ͺ() {
        List<String> arrayList = new ArrayList();
        try {
            arrayList = PackageManagerEx.getSystemWhiteList("freeFormList");
        } catch (Throwable th) {
            Logger.e("GameModeRomSupport", "get freeformlist error");
        }
        return arrayList;
    }
}
